package cn.apestar.modules.sys.utils;

import java.util.List;

import cn.apestar.common.utils.CacheUtils;
import cn.apestar.common.utils.SpringContextHolder;
import cn.apestar.modules.sys.entity.Institution;
import cn.apestar.modules.sys.service.InstitutionService;

public class InstitutionUtils {

    public static final String CACHE_SELLER_LIST = "sellerList";

    private static InstitutionService institutionService = SpringContextHolder.getBean(InstitutionService.class);

    /**
     * 获取当前用户授权的区域
     *
     * @return
     */
    public static List<Institution> getAgentList(Institution institution) {
        @SuppressWarnings("unchecked")
        String keys = CACHE_SELLER_LIST + institution.getId();
        List<Institution> sellerList = (List<Institution>) CacheUtils.get(CacheUtils.SYS_SELLER, keys);
        if (sellerList == null) {
            sellerList = institutionService.findList(institution);
            CacheUtils.put(CacheUtils.SYS_SELLER, keys, sellerList);
        }
        return sellerList;
    }
}
